﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SalesTaxes
{


    public class CommodityWrapper : ITaxable
    {
        private ITaxable _commodity = null;

        private string _name = string.Empty;

        public string Name
        {
            get { return _name; }
        }

        private double _wrapperTaxRate = 0.0f;

        public double WrapperTaxRate
        {
            get { return _wrapperTaxRate; }
        }

        public double TaxRate
        {
            get { return _commodity.TaxRate + _wrapperTaxRate; }
        }

        public decimal PreTaxPrice
        {
            get { return this._commodity.PreTaxPrice; }
        }

        private CommodityWrapper() { }

        public CommodityWrapper(ITaxable commodity, string name, double wrapperTaxRate)
        {
            this._commodity = commodity;
            this._name = name;
            this._wrapperTaxRate = wrapperTaxRate;
        }

        public decimal Cost()
        {
            decimal beforeRound = decimal.Round(this.PreTaxPrice * (decimal)TaxRate + PreTaxPrice, 2, MidpointRounding.AwayFromZero);
            int unit = (int)(beforeRound * 100) % 10;
            return ((unit < 5 && unit > 0) ? (beforeRound - (beforeRound * 100) % 10 / 100 + 0.05M) : beforeRound);
        }


    }
}
